package cn.tedu.charging.order.config;

import cn.tedu.charging.common.constant.AmqpDeclareConst;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 订单模块参考接口文件 声明一组死信延迟结构
 */
@Configuration
@Slf4j
public class DeclareConfiguration {

    @Bean
    public Exchange delayExchange(){
        return new FanoutExchange(AmqpDeclareConst.DELAY_BILL_EX);
    }
    @Bean
    public Exchange dlxExchange(){
        return new DirectExchange(AmqpDeclareConst.DELAY_BILL_DL_EX);
    }
    //声明延迟队列 绑定死信交换机和死信路由
    @Bean
    public Queue delayQueue(){
        return QueueBuilder.nonDurable(AmqpDeclareConst.DELAY_BILL_QUEUE)
                .deadLetterExchange(AmqpDeclareConst.DELAY_BILL_DL_EX)
                .deadLetterRoutingKey(AmqpDeclareConst.DELAY_BILL_DL_RK).build();
    }
    //声明死信队列
    @Bean
    public Queue dlxQueue(){
        return new Queue(AmqpDeclareConst.DELAY_BILL_DL_QUEUE, false);
    }
    //延迟队列和延迟交换机
    @Bean
    public Binding delayBinding(){
        return BindingBuilder
                .bind(delayQueue())
                .to(delayExchange())
                .with("").noargs();
    }
    @Bean
    public Binding dlxBinding(){
        return BindingBuilder
                .bind(dlxQueue())
                .to(dlxExchange())
                .with(AmqpDeclareConst.DELAY_BILL_DL_RK).noargs();
    }


}
